const CryptoJS = require('crypto-js') // 引用AES源码js

const key = CryptoJS.enc.Latin1.parse('654321woxu123456') // 十六位十六进制数作为密钥

const iv = CryptoJS.enc.Latin1.parse('ABCDEF1234123412') // 十六位十六进制数作为密钥偏移量

// const key1 = CryptoJS.enc.Utf8.parse("654321woxu123456"); //十六位十六进制数作为密钥

// const iv1 = CryptoJS.enc.Utf8.parse('ABCDEF1234123412'); //十六位十六进制数作为密钥偏移量

// 加密方法
export function Encrypt(word) {
  const srcs = CryptoJS.enc.Utf8.parse(word)

  const encrypted = CryptoJS.AES.encrypt(srcs,
    key,
    {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    })

  return encrypted.toString()

  // let srcs = CryptoJS.enc.Utf8.parse(word);

  // let encrypted = CryptoJS.AES.encrypt(srcs, key, {  mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });

  // return encrypted.ciphertext.toString().toUpperCase();
}

// 解密方法

export function Decrypt(data) {
  var stime = new Date().getTime()
  var decrypt = CryptoJS.AES.decrypt(data, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  })
  var result = JSON.parse(CryptoJS.enc.Utf8.stringify(decrypt).toString())
  var etime = new Date().getTime()
  console.log('aes的加密时间' + (etime - stime))
  return result

  // let encryptedHexStr = CryptoJS.enc.Hex.parse(word);

  // let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);

  // let decrypt = CryptoJS.AES.decrypt(srcs, key, {  mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });

  // let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);

  // return decryptedStr.toString();
}

function EncryptData(word, key, iv) {

}

